# ------------------------------------------------
# Figures for A Randomized Experiment  Evaluating Survey Mode Effects for Video Interviewing
# ------------------------------------------------

# Install software
# install.packages(c("coefplot", "estimatr"))

# librarires ----
library(foreign)
library(ggplot2)
library(tidyverse)
library(reshape2)
library(coefplot)


# load data ----

library(readxl)

Figure2 <- read_excel("/Users/kyleendres/Dropbox/SSRI_KE/Mode Experiments/PSRM_Figures/ProblemCount.xlsx")
View(Figure2)
Figure3 <- read_excel("/Users/kyleendres/Dropbox/SSRI_KE/Mode Experiments/PSRM_Figures/ItemNonresponse.xlsx")
View(Figure3)
Figure4 <- read_excel("/Users/kyleendres/Dropbox/SSRI_KE/Mode Experiments/PSRM_Figures/Straightlining.xlsx")
View(Figure4)
Figure5 <- read_excel("/Users/kyleendres/Dropbox/SSRI_KE/Mode Experiments/PSRM_Figures/SocialDesirability.xlsx")
View(Figure5)
Figure6 <- read_excel("/Users/kyleendres/Dropbox/SSRI_KE/Mode Experiments/PSRM_Figures/FeelingTherm.xlsx")
View(Figure6)
Figure7 <- read_excel("/Users/kyleendres/Dropbox/SSRI_KE/Mode Experiments/PSRM_Figures/Paper.xlsx")
View(Figure7)

## Problem Count
## Figure 2
ggplot(Figure2, aes(x=Coef, y=fct_relevel(Comparison, "Within Subject (Online v. Combined)", "Within Subject (Online v. In-person)", "Within Subject (Online v. Video)", "Between Subject (Video v. In-person)"))) +
  geom_point(size=2) +
  geom_errorbarh(aes(xmin=lwr, xmax=upr), height =0) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  geom_vline(xintercept=0) +
  xlim(-.8, .8) +
  labs(caption="Note: Reported are the differences in the mean number of issues mentioned with 95% confidence intervals.
       Sample sizes for each condition are online=156, video=78, in-person=79.")+
  xlab("") +
  ylab("") +
  theme(legend.position="none")+ 
  theme(legend.title = element_blank())+
  theme(plot.title = element_text(hjust=0.5))
ggsave("Figure2.pdf", width=6.5, height=3.5, units="in")

## Item Nonresponse
## Figure 3
ggplot(Figure3, aes(x=Coef, y=fct_relevel(Comparison, "Within Subject (Online v. Combined)", "Within Subject (Online v. In-person)", "Within Subject (Online v. Video)", "Between Subject (Video v. In-person)"))) +
  geom_point(size=2) +
  geom_errorbarh(aes(xmin=lwr, xmax=upr), height =0) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  geom_vline(xintercept=0) +
  xlim(-30, 30) +
  labs(caption="Note: Reported are the differences in means across indicated modes with 95% confidence intervals.
       Samples sizes for each condition are online=156, video=78, in-person=79.")+
  xlab("") +
  ylab("") +
  theme(legend.position="none")+ 
  theme(legend.title = element_blank())+
  theme(plot.title = element_text(hjust=0.5))
ggsave("Figure3.pdf", width=6.5, height=3.5, units="in")

## Straightlining
## Figure 4
ggplot(Figure4, aes(x=Coef, y=fct_relevel(Comparison, "Within Subject (Online v. Combined)", "Within Subject (Online v. In-person)", "Within Subject (Online v. Video)", "Between Subject (Video v. In-person)"))) +
  geom_point(size=2) +
  geom_errorbarh(aes(xmin=lwr, xmax=upr), height =0) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  geom_vline(xintercept=0) +
  xlim(-30, 30) +
  labs(caption="Note: Reported are the differences in means across indicated modes with 95% confidence intervals.
       Sample sizes for each condition are online=156, video=78, in-person=79.")+
  xlab("") +
  ylab("") +
  theme(legend.position="none")+ 
  theme(legend.title = element_blank())+
  theme(plot.title = element_text(hjust=0.5))
ggsave("Figure4.pdf", width=6.5, height=3.5, units="in")



## Social Desirability
## Figure5
ggplot(Figure5, aes(x=Coef, y=fct_relevel(Comparison, "Within Subject (Online v. Combined)", "Within Subject (Online v. In-person)", "Within Subject (Online v. Video)", "Between Subject (Video v. In-person)"))) +
  geom_point(size=2) +
  geom_errorbarh(aes(xmin=lwr, xmax=upr), height =0) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  geom_vline(xintercept=0) +
  xlim(-.12, .12) +
  facet_wrap(~Test, ncol=1, scales="free_y") +
  labs(caption="Note: Reported is the difference in means with 95% confidence intervals.
Questions are recoded to range from 0 to 1, with larger values indicating more hostility towards the group.
       Samples sizes for each condition are online=156, video=78, in-person=79.")+
  xlab("") +
  ylab("") +
  theme(legend.position="none")+ 
  theme(legend.title = element_blank())+
  theme(plot.title = element_text(hjust=0.5))
ggsave("Figure5.pdf", width=6.5, height=3.5, units="in")


## Feeling Thermometers Only
## Figure 6
ggplot(Figure6, aes(x=Coef, y=fct_relevel(Comparison, "Within Subject (Online v. Combined)", "Within Subject (Online v. In-person)", "Within Subject (Online v. Video)", "Between Subject (Video v. In-person)"))) +
  geom_point(size=2) +
  geom_errorbarh(aes(xmin=lwr, xmax=upr), height =0) +
  theme_bw() +
  theme(panel.grid = element_blank()) +
  geom_vline(xintercept=0) +
  xlim(-20, 20) +
  facet_wrap(~Test, ncol=1, scales="free_y") +
  labs(caption="Note: Reported is the difference in means with 95% confidence intervals.")+
  xlab("") +
  ylab("") +
  theme(legend.position="bottom")+ 
  theme(legend.title = element_blank())+
  theme(plot.title = element_text(hjust=0.5))
ggsave("Figure6.pdf", width=6.5, height=6, units="in")

## Paper Questionnaire Responses
## Figure 7

ggplot(Figure7, aes(x=variable, y=m, fill=mode)) + 
  geom_col(position="dodge", width=0.5) +
  geom_errorbar(aes(ymin=lwr, ymax=upr), width=0.2, position=position_dodge(0.5)) +
  theme_bw() +
  scale_fill_grey(start = 0.4, end = 0.8, na.value = "red")+
  theme(panel.grid = element_blank()) +
  xlab("") +
  ylab("Strongly Disagree to Strongly Agree (0 to 6)") +
  theme(legend.position = "bottom")
ggsave("Figure7.pdf", width=6.5, height=6, units="in")